package com.baomidou.ant.controller;

import com.baomidou.ant.common.Result;
import com.baomidou.ant.entity.PvpRecord;
import com.baomidou.ant.service.IPvpRecordService;
import com.baomidou.ant.vo.Response.ResponseMyPropsVo;
import com.baomidou.ant.vo.Response.ResponseMyPvpRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-03-24
 */
@RestController
@RequestMapping("/pvp-record")
public class PvpRecordController {
    @Autowired
    private IPvpRecordService pvpRecordService;


    //战绩显示
    @GetMapping("/listRecord/{userId}")
    public Result listRecord(@PathVariable Integer userId){
        QueryWrapper<PvpRecord> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        PvpRecord record=pvpRecordService.getOne(queryWrapper);
        ResponseMyPvpRecordVo vo=new ResponseMyPvpRecordVo();
        BeanUtils.copyProperties(record,vo);
        if(record.getWin()==0){
            vo.setWinningRate(0.0);
        }else{
            Double rate=(double)record.getWin()/(double)record.getTotal()*100;
            vo.setWinningRate(Double.parseDouble(String.format("%.2f",rate)));
        }

        return Result.getSuccess().setData(vo);
    }


}
